package com.fourGirlsAndADude.mobileDRT;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.att.intern.webservice.Incident;
import com.att.intern.webservice.Webservice;
import com.att.intern.webservice.Webservice.GeolocInvalidException;
import com.att.intern.webservice.Webservice.TokenInvalidException;

public class AddActivity extends Activity {

	// Create a new Incident class object for the new damage assessment screen
	static Incident aIncident = new Incident();
	static String picture = new String("");


	// 5 prepopulated events from GeolocSearch, Not editable
	TextView glc;
	TextView state, pM, buildingName, address;
	// Buttons at the top of the screen and bottom of the screen
	ImageView camera, save, delete;
	// Group 1: 1st group of editable fields 4 EditText fields and 3 Drop Boxes
	EditText requesterIDedit, contactNum, initialRptDate, workReqNum;
	Spinner year, type, name, propType;
	// Group 2: NON-CO Facility, group of editable fields 2 Drop Boxes
	Spinner commercialPower, onGenerator;
	// Group 3: Any Facility, group of editable fields 5 drop boxes
	Spinner damage, mobCo, unoccupiable, buildingStatus, creLead;
	// Group 4: Estimated Costs group of editable fields 2 EditText fields
	EditText capital, expense;
	// Group 5: categories group of editable fields drop boxes
	Spinner elecIssue, elecClosed, envirIssue, envirClosed, fgIssue, fgClosed,
			genIssue, genClosed, waterIssue, waterClosed, groundsIssue,
			groundsClosed, mechIssue, mechClosed, otherIssue, otherClosed,
			plumbIssue, plumClosed, roofIssue, roofClosed, safeIssue,
			safeClosed, structIssue, structClosed;
	// Group 6: last fields group of editable fields 4 EditTexts, 1 DropBox
	EditText assessment, status, compDate, notes;
	Spinner rep_OC;

	// Adapters for spinners
	private ArrayAdapter<String> yearAdapter;
	private ArrayAdapter<String> typeAdapter;
	private ArrayAdapter<String> nameAdapter;

	// ArrayList for spinners
	private ArrayList<String> yearArrayList = new ArrayList<String>();
	private ArrayList<String> nameArrayList = new ArrayList<String>();

	private int yearSelected;
	private String nameSelected;
	private String reportStatusSelected;
	private String propertyTypeSelected;
	private String commercialPowerSelected;
	private String onGeneratorSelected;
	private String damageSelected, mobCoSelected, unoccupiableSelected,
			buildingStatusSelected, creLeadSelected;
	private String elecIssueSelected, elecClosedSelected, envirIssueSelected,
			envirClosedSelected, fgIssueSelected, fgClosedSelected,
			genIssueSelected, genClosedSelected, waterIssueSelected,
			waterClosedSelected, groundsIssueSelected, groundsClosedSelected,
			mechIssueSelected, mechClosedSelected, otherIssueSelected,
			otherClosedSelected, plumbIssueSelected, plumbClosedSelected,
			roofIssueSelected, roofClosedSelected, safetyIssueSelected,
			safetyClosedSelected, structIssueSelected, structClosedSelected;

	ImageView add;
	Button submit;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add);
		// 5 prepopulated fields
		final int geolocint = this.getIntent().getIntExtra("GLC", 0);
		final String sessionTokenId = this.getIntent()
				.getStringExtra("SESSION");
		final String userNameStr = this.getIntent().getStringExtra("USER");
		//Log.d("DEBUG", "user name string: "+userNameStr);
		final String authorizationType = this.getIntent().getStringExtra(
				"AUTHTYPE");

		String statestr = this.getIntent().getStringExtra("STATE");
		String pmStr = this.getIntent().getStringExtra("PM");
		String buildingStr = this.getIntent().getStringExtra("BUILDINGNAME");
		String addressStr = this.getIntent().getStringExtra("ADDRESS");
		// Toast Messages

		Context context2 = getApplicationContext();
		final Webservice test = new Webservice(context2);
		final Toast success = Toast.makeText(context2, "Saved!",
				Toast.LENGTH_SHORT);
		final Toast fail1 = Toast.makeText(context2, "Fail!",
				Toast.LENGTH_SHORT);
		final Toast fail2 = Toast.makeText(context2, "No!", Toast.LENGTH_SHORT);

		glc = (TextView) findViewById(R.id.GLC);
		glc.setText(Integer.toString(geolocint));
		state = (TextView) findViewById(R.id.State);
		state.setText(statestr);
		pM = (TextView) findViewById(R.id.PM);
		pM.setText(pmStr);
		buildingName = (TextView) findViewById(R.id.BuildingName);
		buildingName.setText(buildingStr);
		address = (TextView) findViewById(R.id.Address);
		address.setText(addressStr);

		// Add, save, cancel on top
		camera = (ImageView) findViewById(R.id.camera);
		camera.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				picture();
			}

		});
		save = (ImageView) findViewById(R.id.save);
		save.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.d("DEBUG", "Clicked on save");
				// Group 1
				String requesterId = requesterIDedit.getText().toString();
				Log.d("Incident Object", "requester id check 1: " + requesterId);
				String contactNumber = contactNum.getText().toString();
				Log.d("Incident Object", "contact num check 1: "
						+ contactNumber);
				String initialReportDate = initialRptDate.getText().toString();
				Log.d("Incident Object", "initialreportdate check 1: "
						+ initialReportDate);
				String workRecordNumber = workReqNum.getText().toString();
				// Group 2
				// Group 3
				// Group 4
				String estCapCost = capital.getText().toString();
				Log.d("Incident Object", "estCapCost check 1: " + estCapCost);
				String estExpenseCost = expense.getText().toString();
				Log.d("Incident Object", "estExpenseCost check 1: "
						+ estExpenseCost);
				// Group 5
				// Group 6
				String assessNotes = assessment.getText().toString();
				Log.d("Incident object", "assessnotes check 1: " + assessNotes);
				String statusNotes = status.getText().toString();
				Log.d("Incident object", "statusNotes check 1: " + statusNotes);
				String compltnDate = compDate.getText().toString();
				Log.d("Incident object", "completiondate check 1: "
						+ compltnDate);
				String incidentNotes = notes.getText().toString();
				Log.d("Incident object", "incidentNotes check 1: "
						+ incidentNotes);

				// Save all the fields to the incident object
				// Prepopulated fields
				aIncident.setGeoLoc(geolocint);
				aIncident.setState(state.getText().toString());
				aIncident.setPMAttuid(pM.getText().toString());
				aIncident.setBuildingName(buildingName.getText().toString());
				aIncident.setBuildingAddress(address.getText().toString());
				// Group 1
				try {
					aIncident.setIncidentYear(yearSelected);
					Log.d("Incident Object", "yearSelected: " + yearSelected);
				} catch (NumberFormatException e) {
					Log.d("Catch", "Number format exception");
				}
				aIncident.setReqATTUID(requesterId);
				Log.d("Incident Object", "requester id check 2: " + requesterId);
				aIncident.setContactPhone(contactNumber);
				Log.d("Incident Object", "contact num check 2: "
						+ contactNumber);
				aIncident.setInitialRptDate(initialReportDate);
				Log.d("Incident Object", "initialreportdate check 2: "
						+ initialReportDate);
				aIncident.setEventName(nameSelected);
				aIncident.setBuildingType(propertyTypeSelected);
				Log.d("Incident Object", "property type check 2: "
						+ propertyTypeSelected);
				aIncident.setWorkReqNumber(workRecordNumber);
				Log.d("Incident Object", "workRecordNum: " + workRecordNumber);
				// Group 2
				aIncident.setComPowerIndicator(commercialPowerSelected);
				Log.d("Incident Object", "commercial power check: "
						+ commercialPowerSelected);
				aIncident.setOnGeneratorIndicator(onGeneratorSelected);
				Log.d("Incident Object", "ongenerator: " + onGeneratorSelected);
				// Group 3
				aIncident.setCreLead(creLeadSelected);
				Log.d("Incident Object", "cre lead: " + creLeadSelected);
				aIncident.setBuildingStatus(buildingStatusSelected);
				Log.d("Incident Object", "buildStat: " + buildingStatusSelected);
				aIncident.setUnOccupiableIndicator(unoccupiableSelected);
				Log.d("Incident Object", "unoccupiable: "
						+ unoccupiableSelected);
				aIncident.setMobCOIndicator(mobCoSelected);
				Log.d("Incident Object", "mobCo: " + mobCoSelected);
				aIncident.setDamageIndicator(damageSelected);
				Log.d("Incident Object", "damage: " + damageSelected);
				// Group 4
				aIncident.setEstCapCost(Integer.parseInt(estCapCost));
				Log.d("Incident Object", "estCapCost check 2: " + estCapCost);
				aIncident.setEstExpenseCost(Integer.parseInt(estExpenseCost));
				Log.d("Incident Object", "estExpenseCost check 2: "
						+ estExpenseCost);
				// Group 5
				aIncident.setElecIssueIndicator(elecIssueSelected);
				Log.d("Incident Object", "elecIssueSelected: "
						+ elecIssueSelected);
				aIncident.setElecIssueClsdIndicator(elecClosedSelected);
				Log.d("Incident Object", "elecIssueSelected: "
						+ elecClosedSelected);
				aIncident.setEnvIssueIndicator(envirIssueSelected);
				Log.d("Incident Object", "envirIssueSelected: "
						+ envirIssueSelected);
				aIncident.setEnvIssueClsdIndicator(envirClosedSelected);
				Log.d("Incident Object", "envirClosedSelected: "
						+ envirClosedSelected);
				aIncident.setFenceGateIssueIndicator(fgIssueSelected);
				Log.d("Incident Object", "envirClosedSelected: "
						+ fgIssueSelected);
				aIncident.setFenceGateIssueClsdIndicator(fgClosedSelected);
				Log.d("Incident Object", "fgIssueClosed: " + fgClosedSelected);
				aIncident.setGenIssueIndicator(genIssueSelected);
				Log.d("Incident Object", "genIssueSelected: "
						+ genIssueSelected);
				aIncident.setGenIssueClsdIndicator(genClosedSelected);
				Log.d("Incident Object", "genClosedSelected: "
						+ genClosedSelected);

				aIncident.setWaterIssueIndicator(waterIssueSelected);
				Log.d("Incident Object", "waterIssueSelected: "
						+ waterIssueSelected);
				aIncident.setWaterIssueClsdIndicator(waterClosedSelected);
				Log.d("Incident Object", "waterClosedSelected: "
						+ waterClosedSelected);
				aIncident.setGroundsIssueIndicator(groundsIssueSelected);
				Log.d("Incident Object", "groundsIssueSelected: "
						+ groundsIssueSelected);
				aIncident.setGroundsIssueClsdIndicator(groundsClosedSelected);
				Log.d("Incident Object", "groundsClosedSelected: "
						+ groundsClosedSelected);
				aIncident.setMechIssueIndicator(mechIssueSelected);
				Log.d("Incident Object", "mechIssueSelected: "
						+ mechIssueSelected);
				aIncident.setMechIssueClsdIndicator(mechClosedSelected);
				Log.d("Incident Object", "mechClosedSelected: "
						+ mechClosedSelected);
				aIncident.setOtherIssueIndicator(otherIssueSelected);
				Log.d("Incident Object", "otherIssueSelected: "
						+ otherIssueSelected);
				aIncident.setOtherIssueClsdIndicator(otherClosedSelected);
				Log.d("Incident Object", "otherClosedSelected: "
						+ otherClosedSelected);
				aIncident.setPlumbIssueIndicator(plumbIssueSelected);
				Log.d("Incident Object", "plumbIssueSelected: "
						+ plumbIssueSelected);
				aIncident.setPlumbIssueClsdIndicator(plumbClosedSelected);
				Log.d("Incident Object", "plumbClosedSelected: "
						+ plumbClosedSelected);
				aIncident.setRoofsIssueIndicator(roofIssueSelected);
				Log.d("Incident Object", "roofIssueSelected: "
						+ roofIssueSelected);
				aIncident.setRoofsIssueClsdIndicator(roofClosedSelected);
				Log.d("Incident Object", "roofClosedSelected: "
						+ roofClosedSelected);
				aIncident.setSafetyIssueIndicator(safetyIssueSelected);
				Log.d("Incident Object", "safetyIssueSelected: "
						+ safetyIssueSelected);
				aIncident.setSafetyIssueClsdIndicator(safetyClosedSelected);
				Log.d("Incident Object", "safetyClosedSelected: "
						+ safetyClosedSelected);
				aIncident.setStructIssueIndicator(structIssueSelected);
				Log.d("Incident Object", "structIssueSelected: "
						+ structIssueSelected);
				aIncident.setStructIssueClsdIndicator(structClosedSelected);
				Log.d("Incident Object", "structClosedSelected: "
						+ structClosedSelected);
				// Group 6
				aIncident.setAssessNotes(assessNotes);
				Log.d("Incident Object", "assessNotes check 2: " + assessNotes);
				aIncident.setStatusNotes(statusNotes);
				Log.d("Incident Object", "statusNotes check 2: " + statusNotes);
				aIncident.setCompltnDate(compltnDate);
				Log.d("Incident Object", "compltnDate check 2: " + compltnDate);
				aIncident.setIncidentNotes(incidentNotes);
				Log.d("Incident Object", "incidentNotes check 2: "
						+ incidentNotes);
				aIncident.setIncidentStatus(reportStatusSelected);
				Log.d("Incident Object", "report status check 2: "
						+ reportStatusSelected);

				// Try to add the incident
				try {
					Log.d("DEBUG", "Entered try");
					Log.d("Print session", "SessionToken: " + sessionTokenId);

					test.addIncident(sessionTokenId, aIncident);
					success.show();
//					Intent i = new Intent(getBaseContext(),
//							SearchableActivity.class);
//					i.putExtra("AUTHORIZATION_TYPE", authorizationType);
//					i.putExtra("TOKEN_ID", sessionTokenId);
//					i.putExtra("USER_NAME", userNameStr);
//					startActivity(i);
				} catch (NullPointerException e) {
					e.printStackTrace();
				} catch (TokenInvalidException e) {
					Log.d("DEBUG", "Entered catch TokenInvalidException");
					fail1.show();
					e.printStackTrace();
				} catch (GeolocInvalidException e) {
					Log.d("DEBUG", "Entered catch GeolocInvalidException");
					fail2.show();
					e.printStackTrace();
				}
			}// end onclick

		});
		delete = (ImageView) findViewById(R.id.delete);
		delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.d("AddAssessmentActivity", "Pressed cancel");

				fail2.show();
				Intent i = new Intent();
				i.setClassName("com.fourGirlsAndADude.mobileDRT",
						"com.fourGirlsAndADude.mobileDRT.LoginActivity");
				startActivity(i);
				finish();
			}

		});
		
		submit=(Button)findViewById(R.id.SubmitIncidentButtonBottom);
		submit.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				Intent i = new Intent(getBaseContext(),
				SearchableActivity.class);
				i.putExtra("PictureFile", picture);
				i.putExtra("AUTHORIZATION_TYPE", authorizationType);
				i.putExtra("SESSION_TOKEN", sessionTokenId);
				i.putExtra("USERNAME", userNameStr);
				startActivity(i);				
			}
			
		});

		// Group 1
		year = (Spinner) findViewById(R.id.eventYear_dropdown);
		yearAdapter = new ArrayAdapter<String>(AddActivity.this,
				android.R.layout.simple_list_item_1, getList(R.array.eventYear));
		yearAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		year.setAdapter(yearAdapter);
		year.setOnItemSelectedListener(new yearOnSelectedItemClickListener());

		// eventYear.setSelection(0);
		requesterIDedit = (EditText) findViewById(R.id.requesterIDinput);
		requesterIDedit.setText(userNameStr, TextView.BufferType.EDITABLE);
		contactNum = (EditText) findViewById(R.id.contactNumber);
		initialRptDate = (EditText) findViewById(R.id.CurrentDate);
		// Resource:
		// http://stackoverflow.com/questions/8654990/how-can-i-get-current-date-in-android
		Calendar c = Calendar.getInstance();
		System.out.println("Current time => " + c.getTime());
		SimpleDateFormat df = new SimpleDateFormat("MMM-dd-yyyy");
		String formattedDate = df.format(c.getTime());
		initialRptDate.setText(formattedDate, TextView.BufferType.EDITABLE);

		type = (Spinner) findViewById(R.id.eventType_dropdown);
		typeAdapter = new ArrayAdapter<String>(AddActivity.this,
				android.R.layout.simple_spinner_dropdown_item,
				getList(R.array.plzSelectYear));
		typeAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		type.setAdapter(typeAdapter);
		type.setOnItemSelectedListener(new typeOnSelectedItemClickListener());

		name = (Spinner) findViewById(R.id.eventName_dropdown);
		nameAdapter = new ArrayAdapter<String>(AddActivity.this,
				android.R.layout.simple_spinner_dropdown_item,
				getList(R.array.plzSelectYear));
		nameAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		name.setAdapter(nameAdapter);
		name.setOnItemSelectedListener(new nameOnSelectedItemClickListener());

		propType = (Spinner) findViewById(R.id.PropertyType_dropdown);
		propType.setOnItemSelectedListener(new PropertyTypeOnSelectedItemClickListener());
		workReqNum = (EditText) findViewById(R.id.WorkRequestNumber);

		// Group 2
		commercialPower = (Spinner) findViewById(R.id.commercialPower);
		commercialPower
				.setOnItemSelectedListener(new CommercialPowerOnSelectedItemClickListener());
		onGenerator = (Spinner) findViewById(R.id.onGenerator);
		onGenerator
				.setOnItemSelectedListener(new onGeneratorOnItemSelectedListener());

		// Group 3
		damage = (Spinner) findViewById(R.id.damaged);
		damage.setOnItemSelectedListener(new DamagedOnItemSelectedListener());
		mobCo = (Spinner) findViewById(R.id.mobilityCO);
		mobCo.setOnItemSelectedListener(new mobCoOnItemSelectedListener());
		unoccupiable = (Spinner) findViewById(R.id.unoccupiable);
		unoccupiable
				.setOnItemSelectedListener(new unoccupiableOnItemSelectedListener());
		buildingStatus = (Spinner) findViewById(R.id.buildingStatus);
		buildingStatus
				.setOnItemSelectedListener(new buildingStatusOnItemSelectedListener());
		creLead = (Spinner) findViewById(R.id.crelead);
		creLead.setOnItemSelectedListener(new creLeadOnItemSelectedListener());

		// Group 4
		capital = (EditText) findViewById(R.id.capital);
		expense = (EditText) findViewById(R.id.expense);

		// Group 5
		elecIssue = (Spinner) findViewById(R.id.issueElectric);
		elecIssue
				.setOnItemSelectedListener(new elecIssueOnItemSelectedListener());
		elecClosed = (Spinner) findViewById(R.id.closedElectric);
		elecClosed
				.setOnItemSelectedListener(new elecClosedOnItemSelectedListener());
		envirIssue = (Spinner) findViewById(R.id.issueEnviron);
		envirIssue
				.setOnItemSelectedListener(new envirIssueOnItemSelectedListener());
		envirClosed = (Spinner) findViewById(R.id.closedEnviron);
		envirClosed
				.setOnItemSelectedListener(new envirClosedOnItemSelectedListener());
		fgIssue = (Spinner) findViewById(R.id.issueFence);
		fgIssue.setOnItemSelectedListener(new fgIssueOnItemSelectedListener());
		fgClosed = (Spinner) findViewById(R.id.closedFence);
		fgClosed.setOnItemSelectedListener(new fgClosedOnItemSelectedListener());
		genIssue = (Spinner) findViewById(R.id.issueGen);
		genIssue.setOnItemSelectedListener(new genIssueOnItemSelectedListener());
		genClosed = (Spinner) findViewById(R.id.closedGen);
		genClosed
				.setOnItemSelectedListener(new genClosedOnItemSelectedListener());

		waterIssue = (Spinner) findViewById(R.id.issueWater);
		waterIssue
				.setOnItemSelectedListener(new waterIssueOnItemSelectedListener());
		waterClosed = (Spinner) findViewById(R.id.closedWater);
		waterClosed
				.setOnItemSelectedListener(new waterClosedOnItemSelectedListener());
		groundsIssue = (Spinner) findViewById(R.id.issueGround);
		groundsIssue
				.setOnItemSelectedListener(new groundsIssueOnItemSelectedListener());
		groundsClosed = (Spinner) findViewById(R.id.closedGround);
		groundsClosed
				.setOnItemSelectedListener(new groundsClosedOnItemSelectedListener());
		mechIssue = (Spinner) findViewById(R.id.issueMech);
		mechIssue
				.setOnItemSelectedListener(new mechIssueOnItemSelectedListener());
		mechClosed = (Spinner) findViewById(R.id.closedMech);
		mechClosed
				.setOnItemSelectedListener(new mechClosedOnItemSelectedListener());
		otherIssue = (Spinner) findViewById(R.id.issueOther);
		otherIssue
				.setOnItemSelectedListener(new otherIssueOnItemSelectedListener());
		otherClosed = (Spinner) findViewById(R.id.closedOther);
		otherClosed
				.setOnItemSelectedListener(new otherClosedOnItemSelectedListener());
		plumbIssue = (Spinner) findViewById(R.id.issuePlumb);
		plumbIssue
				.setOnItemSelectedListener(new plumbIssueOnItemSelectedListener());
		plumClosed = (Spinner) findViewById(R.id.closedPlumb);
		plumClosed
				.setOnItemSelectedListener(new plumbClosedOnItemSelectedListener());
		roofIssue = (Spinner) findViewById(R.id.issueRoof);
		roofIssue
				.setOnItemSelectedListener(new roofIssueOnItemSelectedListener());
		roofClosed = (Spinner) findViewById(R.id.closedRoof);
		roofClosed
				.setOnItemSelectedListener(new roofClosedOnItemSelectedListener());
		safeIssue = (Spinner) findViewById(R.id.issueSafe);
		safeIssue
				.setOnItemSelectedListener(new safeIssueOnItemSelectedListener());
		safeClosed = (Spinner) findViewById(R.id.closedSafe);
		safeClosed
				.setOnItemSelectedListener(new safeClosedOnItemSelectedListener());
		structIssue = (Spinner) findViewById(R.id.issueStruc);
		structIssue
				.setOnItemSelectedListener(new structIssueOnItemSelectedListener());
		structClosed = (Spinner) findViewById(R.id.closedStruc);
		structClosed
				.setOnItemSelectedListener(new structClosedOnItemSelectedListener());

		// Group 6: last fields group of editable fields 4 EditTexts, 1 DropBox
		assessment = (EditText) findViewById(R.id.assessment);
		status = (EditText) findViewById(R.id.status);
		rep_OC = (Spinner) findViewById(R.id.reportO_C);
		rep_OC.setOnItemSelectedListener(new ReportOpenOnItemSelectedListener());

		compDate = (EditText) findViewById(R.id.completionDate);
		compDate.setText(formattedDate, TextView.BufferType.EDITABLE);
		notes = (EditText) findViewById(R.id.notes);
		
		add=(ImageView)findViewById(R.id.imageView1);
	}// end of oncreate

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add, menu);
		return true;
	}

	private class yearOnSelectedItemClickListener implements
			android.widget.AdapterView.OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			int year;
			try {
				year = Integer.parseInt((String) arg0.getItemAtPosition(arg2));
			} catch (NumberFormatException e) {
				year = 0;
			}
			switch (year) {
			case 2010:
				typeAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.event_type_2010));
				// yearSelected = true;
				break;
			case 2011:
				typeAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.event_type_2011));
				// yearSelected = true;
				break;
			case 2012:
				typeAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.event_type_2012));
				// yearSelected = true;
				break;
			case 2013:
				typeAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.event_type_2013));
				// yearSelected = true;
				break;
			default:
				// yearSelected = false;
				break;
			}
			yearSelected = year;
			typeAdapter
					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			type.setAdapter(typeAdapter);
			// if (yr != 0) {
			// yearSelected = true;
			// } else {
			// yearSelected = false;
			// }
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	}

	private class typeOnSelectedItemClickListener implements
			android.widget.AdapterView.OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Log.v("On type selected", "yr: " + yearSelected);
			switch (arg2) {
			case 0:
				nameAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.plzSelectType));
				break;
			case 1:

				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.hurricane_2013));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.hurricane_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.hurricane_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.hurricane_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));
					break;
				}
				break;
			case 2:
				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.earthquake_2013));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.earthquake_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.earthquake_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.earthquake_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));

					break;
				}
				break;
			case 3:
				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.flood_13));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.flood_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.flood_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.flood_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));

					break;
				}
				break;
			case 4:
				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.icestorm_2013));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.icestorm_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.icestorm_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.icestorm_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));

					break;
				}
				break;
			case 5:
				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.snowstorm_2013));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.snowstorm_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.snowstorm_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.snowstorm_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));

					break;
				}
				break;
			case 6:
				switch (yearSelected) {
				case 2013:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.tornado_2013));
					break;
				case 2012:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.tornado_12));
					break;
				case 2011:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.tornado_11));
					break;
				case 2010:
					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.tornado_10));
					break;
				default:

					nameAdapter = new ArrayAdapter<String>(getBaseContext(),
							android.R.layout.simple_list_item_1,
							getList(R.array.plzSelectType));

					break;
				}
				break;
			case 7:
				nameAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.hurricane_2013));
				break;
			default:
				nameAdapter = new ArrayAdapter<String>(getBaseContext(),
						android.R.layout.simple_list_item_1,
						getList(R.array.plzSelectType));
				break;
			}

			nameAdapter
					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			name.setAdapter(nameAdapter);
			// if (arg2 != 0) {
			// typeSelected = true;
			// } else {
			// typeSelected = false;
			// }
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}

	}

	private class nameOnSelectedItemClickListener implements
			android.widget.AdapterView.OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			nameSelected = arg0.getItemAtPosition(arg2).toString();
			// nameSelected = true;
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}

	}

	private void intializeLists() {
		Log.v("RS", "2");
		// Initialize ArrayList for event Year
		String[] yearStrings = getResources().getStringArray(R.array.eventYear);
		Log.v("RS", "3");
		for (int i = 0; i < yearStrings.length; i++) {
			yearArrayList.add(yearStrings[i]);
		}

		// Initialize ArrayList
		Log.v("RS", "4");
		String[] nameStrings = getResources().getStringArray(
				R.array.plzSelectYear);
		for (int i = 0; i < nameStrings.length; i++) {
			nameArrayList.add(nameStrings[i]);
		}

		Log.v("RS", "5");

	}

	private void intializeList(String[] stringArray) {
		nameArrayList.clear();
		for (String s : stringArray) {
			nameArrayList.add(s);
		}
	}

	private class ReportOpenOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			reportStatusSelected = (String) arg0.getItemAtPosition(arg2);
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
		}
	}

	private class PropertyTypeOnSelectedItemClickListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			propertyTypeSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
		}

	}

	private class CommercialPowerOnSelectedItemClickListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			commercialPowerSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
		}

	}

	private class onGeneratorOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			onGeneratorSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class DamagedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			damageSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}

	private class mobCoOnItemSelectedListener implements OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mobCoSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class unoccupiableOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			unoccupiableSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class buildingStatusOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			buildingStatusSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class creLeadOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			creLeadSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class elecIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			elecIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class elecClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			elecClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class envirIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			envirIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class envirClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			envirClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class fgIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			fgIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class fgClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			fgClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class genIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			genIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class genClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			genClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class waterIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			waterIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class waterClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			waterClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class groundsIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			groundsIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class groundsClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			groundsClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class mechIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mechIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class mechClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mechClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class otherIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			otherIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class otherClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			otherClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class plumbIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			plumbIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class plumbClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			plumbClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class roofIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			roofIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class roofClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			roofClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class safeIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			safetyIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class safeClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			safetyClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class structIssueOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			structIssueSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private class structClosedOnItemSelectedListener implements
			OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			structClosedSelected = (String) arg0.getItemAtPosition(arg2);

		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}

	}

	private ArrayList<String> getList(int arrayResouce) {
		ArrayList<String> lists = new ArrayList<String>();
		String[] strings = getResources().getStringArray(arrayResouce);
		for (String s : strings) {
			lists.add(s);
		}

		return lists;
	}
	
	/* Picture stuff begins */
	
	/**
	 * Takes a picture
	 */
	public void picture(){
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        
        startActivityForResult(cameraIntent, 0); 
        Log.d("AddDamage", "Camera End");
    }

	 /**
	 * Saves the picture after a picture is taken
	 * @param requestCode the request code of the Activity
	 * @param resultCode the result code of the Activity
	 * @param data the data returned by the Activity
	 */
	 protected void onActivityResult(int requestCode, int resultCode, Intent data) {   
	        if (requestCode == 0) {   
	               Log.d("UpdateDamage", "Camera Data Recieved");
	               if(data!=null && data.getExtras()!=null){
	                     Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
	                     //InputStream stream = getContentResolver().openInputStream(data.getData());
	                     MediaStore.Images.Media.insertImage(getContentResolver(), thumbnail, "Picture: "+aIncident.getRecNumber(), "Incident Picture"); 
	                     add.setImageBitmap(thumbnail);
	                     
	                     //save picture
	                     ByteArrayOutputStream stream = new ByteArrayOutputStream();
	                     thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream);
	                     byte[] byteArray = stream.toByteArray();
	                     
	                     
	                     
	                     File pictureFileDir = getDir();

	                     if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {

	                       Log.d("DEBUG_TAG", "Can't create directory to save image.");
	                       Toast.makeText(getApplicationContext(), "Can't create directory to save image.",
	                           Toast.LENGTH_LONG).show();
	                       return;

	                     }

	                     //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
	                     //String date = dateFormat.format(new Date());
	                     String photoFile = "Picture_" + aIncident.getRecNumber() + ".jpg";
	                     System.out.println("Photofile: "+photoFile);

	                     String filename = pictureFileDir.getPath() + File.separator + photoFile;
	                     System.out.println("filename: "+filename);
	                     picture = filename;
	                     File pictureFile = new File(filename);
	                     

	                     try {
	                       FileOutputStream fos = new FileOutputStream(pictureFile);
	                       fos.write(byteArray);
	                       fos.close();
	                       Toast.makeText(getApplicationContext(), "New Image saved:" + photoFile,
	                           Toast.LENGTH_LONG).show();
	                     } 
	                     catch (Exception error) {
	                       Log.d("DEBUG_TAG", "File" + filename + "not saved: "
	                           + error.getMessage());
	                       Toast.makeText(getApplicationContext(), "Image could not be saved.",
	                           Toast.LENGTH_LONG).show();
	                     }
	                   
	                     
	               }

	                   
	                   
	               
	        }
	        Toast picture = Toast.makeText(getApplicationContext(), "Picture taken!", Toast.LENGTH_SHORT);
	        picture.show(); //Toast message
	        
	 }
	 private File getDir() {
         //File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
         //return new File(sdDir, "AddCamera");
        File sdDir = null;
		try {
			sdDir = new File(Environment.getExternalStorageDirectory().getCanonicalPath() + File.separatorChar
			         + Settings.STORAGE_DIRECTORY);
			//sdDir = new File(Envionrment.)
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sdDir;
     }
	
	
	/*End of picture stuff*/

}// end of class
